package vn.elca.training.important_classes_excercise.Question11;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

public class BookStore {
	private Map<String, LinkedList<Book>> m_bookStore = new HashMap<String, LinkedList<Book>>();

	public void addBook(Book book) {
		LinkedList<Book> booksOfAuthor = m_bookStore.get(book.getM_author());
		if (booksOfAuthor == null) {
			booksOfAuthor = new LinkedList<Book>();
			m_bookStore.put(book.getM_author(), booksOfAuthor);
		}
		if (!booksOfAuthor.contains(book))
			booksOfAuthor.add(book);
	}

	public LinkedList<Book> getAllBooksOfAuthor(String author) {
		LinkedList<Book> booksOfAuthor = m_bookStore.get(author);
		return booksOfAuthor;
	}

	public Book getTheMostExpensiveBookOf(String author) {
		LinkedList<Book> booksOfAuthor = m_bookStore.get(author);
		int sizeOfList = booksOfAuthor.size();
		Collections.sort(booksOfAuthor);
		return booksOfAuthor.get(sizeOfList - 1);
	}
}
